package com.guaju.yueshangLife.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.TextView;

import com.guaju.yueshangLife.R;

import java.util.ArrayList;

public class CateTabAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    ArrayList<CateTab> cateTabs;
    Activity activity;
    LayoutInflater layoutInflater;
    private final int myWidth;
    private final int myHeight;

    public void setOnItemClicked(OnItemClicked onItemClicked) {
        this.onItemClicked = onItemClicked;
    }

    private OnItemClicked onItemClicked;


    public CateTabAdapter(ArrayList<CateTab> cateTabs, Activity activity) {
        this.cateTabs = cateTabs;
        this.activity = activity;
        layoutInflater = LayoutInflater.from(activity);
        myWidth = activity.getResources().getDimensionPixelOffset(R.dimen.dp_94);
        myHeight = activity.getResources().getDimensionPixelOffset(R.dimen.dp_30);

    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View inflate = layoutInflater.inflate(R.layout.item_cate, null, false);
        return new CateTabHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        CateTabHolder cateTabHolder = (CateTabHolder) viewHolder;
        cateTabHolder.setContent(cateTabs.get(i));
//        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                onItemClicked.onItemClick(i);
//            }
//        });


    }

    @Override
    public int getItemCount() {
        return cateTabs.size();
    }

    public static class CateTab {
        int id;
        String name;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public CateTab(int id, String name) {
            this.id = id;
            this.name = name;
        }
    }

    public static class CateTabHolder extends RecyclerView.ViewHolder {
        private final RadioButton rb;

        public CateTabHolder(View itemView) {
            super(itemView);
            rb = (RadioButton) itemView;

        }

        public void setContent(CateTab cateTab) {
            rb.setText(cateTab.getName());
            rb.setChecked(false);
        }

    }

    public interface OnItemClicked {
        void onItemClick(int position);
    }
}
